/*
 * MinorEventGuidance.java
 *
 * Created on September 11, 2002, 10:12 AM
 *
 * Copyright (c) 2002 The General Electric Company
 */

package com.ge.healthcare.autosc.processor.shemjob.guidance.dataset;

import com.ge.healthcare.autosc.common.exceptions.BasicException;

/**
 * Guidance information for magnet monitor minor events.
 *
 * @author Daniel S. Horwitz, Compuware Corp.
 *
 * @version AutoSC P5P6
 */
public class MinorEvent
{
    /**
     * Identifier for the currently defined functions.  When a new function
     *  is added, it must be added to this list.
     */
    /** EventFunction of UnknownMajorFunc.  */
    public static final int UNKNOWN_MAJOR_FUNC = 0;
    /** EventFunction of FillNotifFunc.  */
    public static final int FILL_NOTIF_FUNC = 1;
    /** EventFunction of TouchFunc.  */
    public static final int TOUCH_FUNC = 2;
    /** EventFunction of LimitAlarmFunc.  */
    public static final int LIMIT_ALARM_FUNC = 3;
    /** EventFunction of DiscreteAlarmFunc.  */
    public static final int DISCRETE_ALARM_FUNC = 4;
    /** EventFunction of UnknownAlarmFunc.  */
    public static final int UNKNOWN_ALARM_FUNC = 5;
    /** EventFunction of CheckinFunc.  */
    public static final int CHECKIN_FUNC = 6;

    /**
     * Table for converting event function name to event function identifier.
     *  When a new function is added, it must be added to this list.
     */
    private static final String[] functionNameList = new String[] {
        "UnknownMajorFunc",     // UNKNOWN_MAJOR_FUNC
        "FillNotifFunc",        // FILL_NOTIF_FUNC
        "TouchFunc",            // TOUCH_FUNC
        "LimitAlarmFunc",       // LIMIT_ALARM_FUNC
        "DiscreteAlarmFunc",    // DISCRETE_ALARM_FUNC
        "UnknownAlarmFunc",     // UNKNOWN_ALARM_FUNC
        "CheckinFunc"           // CHECKIN_FUNC
    };

    /**
     * Identifier of the event function to perform.
     */
    private int theEventFunction = 0;

    /**
     * Text which is used to identify the event in logs.
     */
    private String theEventText = null;
    
    /**
     * Event Name that uses this function
     */
    private String eventName = null;

    /**
     * Create a magnet monitor minor event guidance instance.
     *
     * @param eventFunctionName The name of the event function to perform.
     *
     * @param eventText The text which is used to identify the event in logs.
     *
     * @exception Exception If the event function name is not one of the
     *  recognized names.
     */
    public MinorEvent( String eventFunctionName, String eventText )
        throws BasicException
    {
        theEventFunction = getIdentifierFor( eventFunctionName );
        theEventText = eventText;
    }

    /**
     * Get the event function identifier for the specified event function
     *  name.
     *
     * @param eventFunctionName The name of the event function to perform.
     *
     * @return Event function identifier for the specified event function name.
     *
     * @exception Exception If the event function name is not one of the
     *  recognized names.
     */
    private int getIdentifierFor( String eventFunctionName ) throws BasicException
    {
        for ( int idx = 0; idx < functionNameList.length; idx += 1 )
        {
            if ( eventFunctionName.equals( functionNameList[idx] ) )
            {
                return idx;
            }
        }
        String message =
            eventFunctionName + " is not a valid EventFunction value";
        throw new BasicException( message );
    }

    /**
     * Get the identifier of the event function to perform.
     *
     * @return The identifier of the event function to perform.
     */
    public int getEventFunction()
    {
        return theEventFunction;
    }

    /**
     * Get the function name of the event function
     * @return The name of the event function.
     */
    public String getEventFunctionName() {
    	return functionNameList[theEventFunction];
    }
    
    /**
     * Get the text which is used to identify the event in logs.
     *
     * @return The text which is used to identify the event in logs.
     */
    public String getEventText()
    {
        return theEventText;
    }

    /**
     * Return a string representation of the object.
     *
     * @return A string representation of the object.
     */
    public String toString()
    {
        return "{" +
               theEventFunction +
               ":" +
               functionNameList[theEventFunction] +
               "," +
               theEventText +
               "}";
    }

    /**
     * Get the minor event name
     * @return String
     */
	public String getEventName() {
		return eventName;
	}

	/**
	 * Set the minor event name
	 * @param minorEventName
	 */
	public void setEventName(String minorEventName) {
		this.eventName = minorEventName;
	}
}
